﻿#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTcpSocket>//通信套接字
#include <QHostAddress>
#include <QMessageBox>//消息对话框
#include <QDebug>
#include "login.h"
#include <QCloseEvent>
#include <QFile>
#include <QPixmap>
#include <QPainter>
#include <QPaintEvent>
#include <WinSock2.h>
#include <QtEndian>
#include <QProcess>
#include <QString>

struct Position{
    uint x;
    uint y;
    uint z;
    char ch;//移动标志'c','s'
};
/*
struct Control{
    char ch1;//身份标志's'
    int l;//长
    int w;//宽
    char ch2;//抓取'1'或释放'0'
};
*/
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

signals:
    void posionPic(Position position);
    void recvAllSuccess();
    void sendPicSuccess(QByteArray byte, uint size);
public:
    void closeEvent(QCloseEvent *event) override;//关闭事件
    void paintEvent(QPaintEvent *event) override;//绘图事件
    // 检测图片并发送
    int detect_picture(QString *ret);
private slots:
    void recv_data();

    void sendPic();

    void on_connectButton_clicked();

    void sendPosition(Position position);

//    void control(Control control);

    void handlerPicPosition(Position posion);

//    void handlerPic(Pic pic);

    void on_recognizeButton_clicked();//识别

    void on_moveButton_clicked();//移动

    void on_grabButton_clicked();//抓取

    void on_releaseButton_clicked();//释放



private:
    Ui::Widget *ui;
    QTcpSocket *socket;
    QByteArray m_data;
    QFile file;
    Login m_login;
    Sqlite* m_ptrSql;
    QString str;

};
#endif // WIDGET_H
